package com.todo.strategy.online.application.api.controller;

import com.todo.common.common.entity.response.BizResponse;
import com.todo.strategy.online.application.convert.StrategyConvert;
import com.todo.strategy.online.application.entity.bo.StrategyInfoBO;
import com.todo.strategy.online.application.service.StrategyInfoService;
import com.todo.strategy.online.service.api.UserStrategyApi;
import com.todo.strategy.online.service.api.response.UserStrategyBaseResponse;
import com.todo.strategy.online.service.api.response.UserStrategyDetailResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author azhebuxing
 * @date 2025/2/27 22:57
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/api/user/strategy")
@Tag(name = "服务端-用户攻略接口", description = "服务端-用户攻略接口")
public class UserStrategyApiController implements UserStrategyApi {

    @Resource
    private StrategyInfoService strategyInfoService;

    @Override
    @Operation(summary = "根据id查询用户攻略信息")
    @PostMapping("/queryUserStrategyById")
    public BizResponse<UserStrategyBaseResponse> queryUserStrategyById(@RequestBody Long userStrategyId) {
        if (userStrategyId == null) {
            return BizResponse.success("查询异常，请刷新后重新操作");
        }
        StrategyInfoBO strategyInfoBO = strategyInfoService.queryStrategyInfoById(userStrategyId);
        return BizResponse.success(StrategyConvert.convertToUserStrategyBaseResponse(strategyInfoBO));
    }

    @Override
    @Operation(summary = "根据id查询用户攻略详情")
    @PostMapping("/queryUserStrategyDetailById")
    public BizResponse<UserStrategyDetailResponse> queryUserStrategyDetailById(@RequestBody Long userStrategyId) {
        if (userStrategyId == null) {
            return BizResponse.success("查询异常，请刷新后重新操作");
        }
        StrategyInfoBO strategyInfoBO = strategyInfoService.queryStrategyInfoById(userStrategyId);
        return BizResponse.success(StrategyConvert.convertToUserStrategyDetailResponse(strategyInfoBO));
    }

    @Override
    @Operation(summary = "根据id列表查询用户攻略信息")
    @PostMapping("/queryUserStrategyList")
    public BizResponse<List<UserStrategyBaseResponse>> queryUserStrategyList(@RequestBody List<Long> strategyIdList) {
        if (CollectionUtils.isEmpty(strategyIdList)) {
            return BizResponse.success("查询异常，请刷新后重新操作");
        }
        List<StrategyInfoBO> strategyInfoBOS = strategyInfoService.queryStrategyInfoByIdList(strategyIdList);
        return BizResponse.success(StrategyConvert.convertToUserStrategyBaseResponseList(strategyInfoBOS));
    }
}
